package com.jwdf.uda.ui.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;

import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.ItemDesignerBinding;
import com.jwdf.uda.ui.activity.UserInfoActivity;
import com.jwdf.uda.ui.adapter.item.UserSimpleItem;
import com.jwdf.uda.utils.ConfigUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Administrator on 2016/5/16.
 */
public class DesignerAdapter extends AbsAdapter<UserSimpleItem> {
    private boolean mIsCurrentUser = false;

    public DesignerAdapter(Context context) {
        super(context);
    }



    public void setCurrentUser(boolean isCurrentUser) {
        this.mIsCurrentUser = isCurrentUser;
    }

    @Override
    protected AbsViewHolder onCreateViewHolder(ViewGroup parent, int itemType) {
        return new UserSimpleViewHolder(mInflater.inflate(R.layout.item_designer, parent, false));
    }

    private class UserSimpleViewHolder extends AbsViewHolder<UserSimpleItem> {
        private ItemDesignerBinding mBinding;

        public UserSimpleViewHolder(View convertView) {
            super(convertView);
            mBinding = DataBindingUtil.bind(convertView);
        }

        @Override
        protected void onBindView(final UserSimpleItem item) {
            final PbBean.PbUserSimple userSimple = item.userSimple;

            boolean isOwner = TextUtils.equals(userSimple.getUserId(), ConfigUtils.getUserId(mBinding.getRoot().getContext()));
            mBinding.setIsOwner(isOwner);
            mBinding.setIsDesigner(userSimple.getIsDesigner());
            ImageLoader.getInstance().displayImage(userSimple.getAvatar().getUrl(),mBinding.ivHeader);
            mBinding.tvNickName.setText(userSimple.getNickname());
            mBinding.tvIntroduction.setVisibility(TextUtils.isEmpty(userSimple.getIntroduction()) ? View.GONE:View.VISIBLE);
            mBinding.tvIntroduction.setText(userSimple.getIntroduction());
            mBinding.ivIsDesigner.setVisibility(userSimple.getIsDesigner() ? View.VISIBLE : View.GONE);
            mBinding.rlHeader.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    UserInfoActivity.start(mBinding.getRoot().getContext(), userSimple.getUserId(), userSimple.getIsDesigner());
                }
            });
        }
    }
}
